home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
encrypt2
/
encrypt.frm
next >
Wrap
Text File
|
1997-08-17
|
4KB
|
155 lines
VERSION 4.00
Begin VB.Form Form1
Caption = "Encryption Example"
ClientHeight = 3750
ClientLeft = 1665
ClientTop = 1740
ClientWidth = 6690
Height = 4155
Left = 1605
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 3750
ScaleWidth = 6690
Top = 1395
Width = 6810
Begin VB.CommandButton Command2
Caption = "Decrypt"
Height = 375
Left = 4800
TabIndex = 3
Top = 3120
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "Encrypt"
Height = 375
Left = 3000
TabIndex = 2
Top = 3120
Width = 1575
End
Begin VB.TextBox Text2
Height = 375
Left = 480
TabIndex = 1
Top = 3120
Width = 2295
End
Begin VB.TextBox Text1
Height = 2535
Left = 480
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 360
Width = 5775
End
End
Attribute VB_Name = "Form1"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Dim Key(1 To 20) As Integer
Private Type cryptrecord
code As Integer
End Type
Private Sub Command1_Click()
Dim crypt As cryptrecord
Dim n As Long
Dim i As Integer
If Len(Text2.Text) < 3 Then
MsgBox "Password must be 3 to 20 characters long.", 0, "Password Needed"
Else
'If password is longer than 20, only use the first 20 characters...
If Len(Text2.Text) > 20 Then
Text2.Text = Left(Text2.Text, 20)
End If
'We'll use the length of the password to repeat it...
For i = 1 To Len(Text2.Text)
Key(i) = Asc(Mid(Text2.Text, i, 1)) + i
Next
'Set i = 1 to be able to increment through Key(i)...
i = 1
'Open the file...
Open "c:\coded.dat" For Random As #1 Len = Len(crypt)
For n = 1 To Len(Text1.Text)
'Add the ASCII value of Key(i) to the ASCII value
'of the next character in Text1.Text...
crypt.code = Asc(Mid(Text1.Text, n, 1)) + Key(i)
'Increment i...
i = i + 1
'If i is larger than the lenght of the password, reset it...
If i > Len(Text2.Text) Then
i = 1
End If
Put #1, n, crypt.code
Next
Close #1
Text1.Text = "Done!"
Text2.Text = ""
End If
End Sub
Private Sub Command2_Click()
Dim crypt As cryptrecord
Dim n, filelength As Long
Dim i As Integer
Dim temp As String * 1
Text1.Text = ""
If Len(Text2.Text) < 3 Then
MsgBox "Password must be 3 to 20 characters long.", 0, "Password Needed"
Else
If Len(Text2.Text) > 20 Then
Text2.Text = Left(Text2.Text, 20)
End If
For i = 1 To Len(Text2.Text)
Key(i) = Asc(Mid(Text2.Text, i, 1)) + i
Next
i = 1
Open "c:\coded.dat" For Random As #1 Len = Len(crypt)
'Divide the file length (bytes) by 2. We used integers
'which take 2 bytes each...
filelength = LOF(1) / 2
For n = 1 To filelength
Get #1, n, crypt.code
temp = Chr(Abs(crypt.code - Key(i)))
i = i + 1
If i > Len(Text2.Text) Then
i = 1
End If
Text1.Text = Text1.Text & temp
Next
Close #1
End If
End Sub